// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)
Vue.config.productionTip = false

let store = new Vuex.Store({
  state: {
    test: {},
    questions: [],
    userinfo: {},
    isShowRule: 0,
    wrongnum: 0,
    alertData:{
      title: '提示',
      text: '我是提示',
      visible: 0,
      btns: ['确定'],
      callback: res=>{
        store.commit('updateAlertData',{visible:0})
      }
    }
  },
  mutations: {
    setUserInfo(state,userinfo){
      state.userinfo = userinfo
    },
    updateUserInfo(state,data){
      Object.assign(state.userinfo,data)
    },
    setTest(state,test){
      state.test = test
    },
    updateTest(state,data){
      Object.assign(state.test,data)
    },
    setQuestions(state,questions){
      state.questions = questions
    },
    showRule(state){
      state.isShowRule = 1
    },
    hideRule(state){
      state.isShowRule = 0
    },
    updateAlertData(state,data){
      Object.assign(state.alertData,data)
    },
    decreaseScore(state,score){
      state.userinfo.score-=score
    },
    useCard(state,key){
      state.userinfo[key]-=1
      if(key=='addtimecardnum'){
        window.sessionStorage.startTime = 60000 + parseInt(window.sessionStorage.startTime)
      }else if(key=='passcardnum'){

      }else if(key=='doublescorecardnum'){

      }
    },
    answer(state,isRight){
      if(isRight){
        state.test.rightnum++
        state.test.score = state.test.rightnum*10
      }else{
        state.wrongnum++
      }
    }
  }
})
var useragent = navigator.userAgent;
if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
  alert('已禁止本次访问：您必须使用微信内置浏览器访问本页面！');
  var opened = window.open('about:blank', '_self');
  opened.opener = null;
  opened.close();
}
axios.get('/gxtest/getWxConfig', {params: {cururl: window.location.href}}).then(res => {
  window.wx.config({
    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
    appId: res.data.appid,  // 必填，公众号的唯一标识
    timestamp: res.data.timestamp,  // 必填，生成签名的时间戳
    nonceStr: res.data.nonceStr,  // 必填，生成签名的随机串
    signature: res.data.signature, // 必填，签名，见附录1
    jsApiList: [
      'chooseImage',
      'onMenuShareTimeline',
      'onMenuShareAppMessage',
      'uploadImage',
      'downloadImage',
      'showMenuItems',
      'showAllNonBaseMenuItem',
      'showOptionMenu'
    ]  // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
  })
})
window.wx.ready(() => {
  window.wx.onMenuShareTimeline({
    title: "快来参加国学测试啦", // 分享标题
    link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
    imgUrl: 'http://game.lzsunspot.com/gxtest/static/images/share-title.jpg', // 分享图标
    success: function () {},
    cancel: function () {}
  })
  window.wx.onMenuShareAppMessage({
    title: "快来参加国学测试啦", // 分享标题
    desc: "快来参加国学测试啦", // 分享描述
    link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
    imgUrl: 'http://game.lzsunspot.com/gxtest/static/images/share-title.jpg', // 分享图标
    success: function () {},
    cancel: function () {}
  })
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
